package http

import (
	"gateway"
	"gateway/core"
)

type Http11Handler struct {
	context core.GatewayContext
}

func BuildContext(path, method string, header map[string]string, body []byte, ip string) core.GatewayContext {
	request := core.NewRequest()
	context := core.NewGatewayContext()
	request.URL = path
	request.Protocol = gateway.HTTP11_PROTOCOL
	request.Method = method
	request.Header = header
	request.Body = body
	request.Ip = ip
	context.Request = request
	return context
}

func NewHttp11Handler(context core.GatewayContext) Http11Handler {
	return Http11Handler{context: context}
}

func (handler Http11Handler) Call() {

	route := NewRoute()
	route.GatewayContext = handler.context
	route.Pre()
	route.Route()
	route.Post()
}
